feat(react-query): add optional @types/react peer dependency 🤖🤖🤖 - #11598
unrevised6419 wants to merge 1 commit into
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: TanStack/query/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthrough
ChangesReact Query type dependencies
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~5 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to This change adds optional React type support for React 18 and 19 and records a patch release. No concrete merge-blocking behavior is evident. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
9e539c6 to
8723ae8
Compare
The shipped .d.ts files import React's types, but the package only declares the `react` runtime peer. TypeScript resolves those imports relative to where the package physically sits, so under pnpm layouts that place it outside the consumer's repo (`virtualStoreType: global`) `react` resolves to the untyped `react/index.js` and every React-derived type silently degrades to `any`. Declaring `@types/react` as an optional peer at `^18 || ^19` lets that resolution land on the consumer's own `@types/react`. It is optional, so JavaScript consumers see no install warning, and the range mirrors the existing `react` peer exactly.
8723ae8 to
3ef211a
Compare
🎯 Changes
Adds
@types/reactas an optional peer dependency of@tanstack/react-query, at*:Why
The published package ships declaration files that import React's types —
import * as React from "react"appears inbuild/modern/useQuery.d.ts,QueryClientProvider.d.ts,HydrationBoundary.d.tsand eight others in 5.103.2 — but the package only declares thereactruntime peer.TypeScript resolves a package's imports from where that package physically sits on disk, and it ignores
NODE_PATH. Most pnpm layouts hide this, because the virtual store lives inside the consumer's ownnode_modulesand the lookup walks up into it. WithvirtualStoreType: global, though, the package physically lives outside the consumer's repository, e.g.~/Library/pnpm/store/v11/links/@/react-query/<version>/<hash>/node_modules/@tanstack/react-query. From there@types/reactis not reachable, soreactresolves to the untyped runtime entry instead:index.js, notindex.d.ts. WithallowJs: truethat is silently accepted and every React-derived type in the public surface degrades toany—ReactNode, thechildrenofQueryClientProviderandHydrationBoundary, the ref and element types threaded through the hooks. Zero compiler errors;tscstill exits 0. That silence is the reason this is worth fixing. Where a consumer's config blocks the JS fallback it fails outright instead.Declaring the optional peer makes that same resolution land on the consumer's
@types/react/index.d.ts.I verified the effect end to end on a real application by injecting these peers through pnpm
packageExtensions: it went from 61 untyped + 6 unresolved React resolutions to 1012/1012 landing on.d.ts, withtscstill exiting 0.Why it's safe
^18 || ^19, mirroring the existingreactpeer exactly, so the types peer makes no version claim the runtime peer does not already make. The repo develops against@types/react@^19.2.7; the union keeps React 18 consumers valid.Precedent
@testing-library/reactdeclares exactly this pair. Within this repo, #10007 did the same thing fortypescriptin@tanstack/eslint-plugin-query, and I matched that package.json's key ordering and shape here.Scope
Deliberately limited to
@tanstack/react-query.react-query-devtools,react-query-persist-clientandreact-query-next-experimentallook like they have the same gap, but I kept this to one package per the contributing guide — happy to extend it here or follow up separately, whichever you prefer.A
patchchangeset is included.✅ Checklist
pnpm run test:pr, or these tests do not apply to this pull request. — manifest-only change with no source or test impact; validated the JSON and checked both files against Prettier.🚀 Release Impact
Summary by CodeRabbit